from os import listdir
from subprocess import call
import os

PA_IN = "pa-4-input/"
PA_OUT = "pa-4-output/"

OUT1 = "out1"
OUT2 = "out2"
DIFF = "diff"

def myrm(files):
	for f in files:
		try:
			os.remove(f)
		except:
			pass

for f in listdir(PA_IN):
	myrm([OUT1, OUT2, DIFF])
	name = f.partition(".")[0]
	kind = f.partition(".")[2]
	if (kind != "ic"): continue
	call("java -cp bin:lib/gearley.jar Main " + PA_IN + f + " >> " + OUT1, shell = True)
	call("java -jar 3ac-emu.jar -q " + OUT1 + " >> " + OUT2, shell = True)
	call("diff " + OUT2 + " " + PA_OUT + name + ".out" + " >> " + DIFF, shell = True)
	if (os.path.getsize(DIFF) > 0):
		print "Error with " + name
		break
	else:
		print "Finished testing " + name
